clear all
global system "linux"

if "${system}" == "linux" {
	*global code "/"
	global code "/"
	global s "/"
}

run "${code}${s}_set-path.do"
cd "${code}/tba_elig"

set obs 1
gen PaboveC = 1
gen PaboveC1 = 1
gen Cutoff = 1
gen notba = 1
gen ltvprev_diff = 1
gen HiP = 1

run _esttab-latex-options.do
qui do "${code}/_labels"

**** 1. Prepayment

foreach Runvar in ltvprev_diff { 
	foreach Sample in 2 { 
		foreach Var in pp forcl {
			eststo clear

			foreach Age of numlist 24(12)60 {
			
				est use "${Estimates}/harp-`Var'`Age'-Sample`Sample'"
				local keepvar "Cutoff 1.Cutoff#c.`Runvar'"
										
				local coef1 "1.Cutoff#c.`Runvar'"			
				local FE2 "Mortgage Rate Bin x MONTH FE"
				label var Cutoff "$ 1[z_i>0]$"
				local coef2 "$ z_i\times 1[z_i>0]$"
				
				eststo
				estadd local llpa "Y"
				estadd local zip_3 "Y"
				estadd local lender "Y"
				estadd local rate_month "Y"
				estadd local control "Y"
			}
				
			esttab using "${table}/harp-`Var'-Sample`Sample'.tex", replace keep(`keepvar') coeflabels(`coef1' "`coef2'") ///
			 ${opts_esttab}  b(%9.4fc) se(%9.4fc) star(* 0.10 ** 0.05 *** 0.01) ///
			 stats(zip_3 lender rate_month control N r2_a, fmt(/* %1s */ %1s %1s %1s %1s %9.0fc %3.2f) ///
			 labels("ZIP3 FE" "Lender FE" "Mortgage Rate X Month FE" "Other Controls" "\midrule N. Obs." "Adj. $ R^2$")) ///
			 mtitle("By Age 24" "By Age 36" "By Age 48" "By Age 60")
			 
		}
	}
}



**** 2. Other loan characteristicredit_score

foreach Sample in 2 {
	eststo clear
	local mtitle 
	foreach n of numlist 1/4 {
		
		est use "${Estimates}/`design'-loanchar-DepVar`n'-Sample`Sample'"
		eststo
		
		local DepVar = e(depvar)
		cap gen `DepVar' = 1
		qui do "${code}/_labels"
		local depvar_label: variable label `DepVar'
		local mtitle "`mtitle' `"`depvar_label'"'"
		
		estadd local control "N"
		estadd local lender "Y"
		estadd local month "Y"
	
		
		local keepvar "Cutoff 1.Cutoff#c.ltvprev_diff"
		estadd local zip_3 "Y"
	
		local coef1 "1.Cutoff#c.ltvprev_diff"
			
	}
			
	
	label var Cutoff "$ 1[z_i>0]$"
	local coef2 "$ z_i\times 1[z_i>0]$"
								
	esttab using "${table}/harp-loanchar-Sample`Sample'.tex", replace keep(`keepvar') coeflabels(`coef1' "`coef2'") ///
	 ${opts_esttab}  b(%9.3fc) se(%9.3fc) star(* 0.10 ** 0.05 *** 0.01) ///
	 stats(zip_3 lender month N r2_a, fmt(%1s %1s %1s %9.0fc %3.2f) ///
	 labels("ZIP3 FE" "Lender FE" "Month FE"  "\midrule N. Obs." "Adj. $ R^2$")) ///
	 mtitle(`mtitle')
 }
 
